﻿using System;
using System.Globalization;
using System.ServiceModel.DomainServices.Client;
using System.Threading;
using System.Windows;
using System.Windows.Browser;
using System.Windows.Controls;
using System.Windows.Media.Imaging;
using Telerik.Windows.Controls;
using Telerik.Windows.Controls.Charting;
using Telerik.Windows.Controls.DomainServices;
using LoadingDataEventArgs = Telerik.Windows.Controls.DomainServices.LoadingDataEventArgs;
using System.Diagnostics;

namespace ExecutiveDashboard_SL1
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
            LocalizationManager.DefaultCulture = new CultureInfo("en-US");
            Thread.CurrentThread.CurrentCulture = LocalizationManager.DefaultCulture;
            this.DataContext = new ViewModel { ItemsCount = 1, SeriesCount = 12 };
            
        }

        void radToggleButton_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            this.UpdateChartImage();
        }

        /// <summary>
        /// Updates the image that is shown when the settings panel is being opened. 
        /// </summary>
        private void UpdateChartImage()
        {
            //radChart.DefaultView.ChartArea.AxisX.AxisLabelsVisibility = Visibility.Collapsed;
            //radChart.DefaultView.ChartArea.AxisY.AxisLabelsVisibility = Visibility.Collapsed;

            //bool showPointMarks = (radChart.SeriesMappings[0].SeriesDefinition as AreaSeriesDefinition).ShowPointMarks;
            //(this.DataContext as ViewModel).ShowPointMarks = false;

            //chartImage.Source = new WriteableBitmap(this.radChart, null);

            //(this.DataContext as ViewModel).ShowPointMarks = showPointMarks;
            //radChart.DefaultView.ChartArea.AxisX.AxisLabelsVisibility = Visibility.Visible;
            //radChart.DefaultView.ChartArea.AxisY.AxisLabelsVisibility = Visibility.Visible;
        }

        void DomainDataSourceLoadingData(object sender, LoadingDataEventArgs e)
        {
            Debug.WriteLine(string.Format("refreshing {0}", (sender as FrameworkElement).Name));
            e.LoadBehavior = LoadBehavior.RefreshCurrent;
        }

        private void OnTwitterButtonClick(object sender, System.Windows.RoutedEventArgs e)
        {
            string twitterShareUrl = string.Format("http://twitter.com/share?text={0}&url={1}&related=Telerik",
                                                   HttpUtility.UrlEncode(string.Format("Check this awesome new Silverlight #TelerikDashboard and win an iPad2. See how here:")),
                                                   "http://demos.telerik.com/silverlight/executivedashboard/Default.aspx?utm_source=twitter&utm_medium=game&utm_campaign=demo");

            HtmlPage.Window.Navigate(new Uri(twitterShareUrl), "_blank");
        }
    }
}